import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_1800/generated/l10n.dart';
import 'package:flutter_1800/pages/home.dart';
import 'package:flutter_1800/tools/config.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/route_manager.dart';

import 'common/color.dart';

void main() {
  runApp(const MyApp());
  // registerWxApi(
  //     appId: AppConfig.WXAppId, universalLink: AppConfig.UniversalLink);

  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle.dark.copyWith(
      statusBarColor: Colors.white, //这里替换你选择的颜色
    ),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final Color primaryColor = Colors.tealAccent;

  @override
  void initState() {
    // WindowManager windowManager = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE))
    // float fps = windowManager.getDefaultDisplay().getRefreshRate();
    // setMode();
  }

  void setMode() async {
    try {
      var modes = await FlutterDisplayMode.supported;
      modes.forEach(print);

      await FlutterDisplayMode.setPreferredMode(modes[1]);

      await FlutterDisplayMode.setHighRefreshRate();

      // setFrameRate(90);

      /// On OnePlus 7 Pro:
      /// #0 0x0 @0Hz // Automatic
      /// #1 1080x2340 @ 60Hz
      /// #2 1080x2340 @ 90Hz
      /// #3 1440x3120 @ 90Hz
      /// #4 1440x3120 @ 60Hz

      /// On OnePlus 8 Pro:
      /// #0 0x0 @0Hz // Automatic
      /// #1 1080x2376 @ 60Hz
      /// #2 1440x3168 @ 120Hz
      /// #3 1440x3168 @ 60Hz
      /// #4 1080x2376 @ 120Hz
    } on PlatformException {
      /// e.code =>
      /// noAPI - No API support. Only Marshmallow and above.
      /// noActivity - Activity is not available. Probably app is in background
    }
  }

  @override
  Widget build(BuildContext context) {
    final easyload = EasyLoading.init();

    return GetMaterialApp(
        title: '妙管省钱',
        builder: (BuildContext context, Widget? child) {
          return easyload(context, child);
        },
        theme: ThemeData(
            brightness: Brightness.light,
            primarySwatch: createMaterialColor(AppConfig.mainColor),
            primaryColor: AppConfig.mainColor,
            textTheme:
                const TextTheme(button: TextStyle(color: Colors.black12)),
            appBarTheme: const AppBarTheme(
                iconTheme: IconThemeData(color: Colors.black),
                titleTextStyle: TextStyle(
                    color: Color.fromARGB(255, 65, 57, 57), fontSize: 20.0),
                color: Colors.white)),
        debugShowCheckedModeBanner: false,
        home: HomePage(),
        localizationsDelegates: const [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          S.delegate,
        ],
        supportedLocales: S.delegate.supportedLocales,
        locale: const Locale('zh'));
  }
}
